package demo;
import java.util.List;
import java.util.ArrayList;
import java.util.Stack;
class Solution {
    static class TreeNode{
        public int val;
        private TreeNode left;
        private TreeNode right;
        public TreeNode(int val)
        {
            this.val = val;
        }
    }
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        if(root == null)
        {
            return list;
        }

        Stack<TreeNode> stack = new Stack<>();
        while(root!=null||!stack.isEmpty())
        {
            while(root!= null)
            {
                stack.push(root);
                root = root.left;
            }
            root = stack.pop();
            list.add(root.val);
            root = root.right;
        }
        return list;

    }
}
public class demo2 {
}
